package com.fairytask.ui.item
{
	import com.fairytask.engine.components.clip.Clip;
	import com.fairytask.engine.define.Filter;
	import com.fairytask.engine.define.ResConfig;
	import com.fairytask.engine.managers.ResManager;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	
	/**
	 * 场景对象 
	 * @author xujh
	 * 
	 */
	public class SceneItem extends Sprite
	{
		//========================================
		private var mapSp		:Sprite = new Sprite();
		private var starSp		:Sprite = new Sprite();
		private var sceneImg	:Clip = new Clip;
		private var lockedImg	:Clip = new Clip;
		
		private var _configID	:int;
		private var _starVal	:int;
		private var _locked	:Boolean;
		private var _fieldID	:String;
		private var _isPass	:Boolean = false;;	//是否已经通过可以挂机
		
		
		public function SceneItem()
		{
			init();
			initEvent();
		}
		
		private function init():void
		{
			addChild(mapSp);
			
			//临时数据
			/*sceneImg.source =  ResConfig.mapResPath + "15010001/15010001_00_12.jpg";
			sceneImg.width	= 80;
			sceneImg.height	= 55;
			mapSp.addChild(sceneImg);*/
			addChild(starSp);
			
			//默认
			lockedImg.source	=	ResConfig.pngResPath + "locked.png";
			lockedImg.x = 40;
			lockedImg.y = 10;
			addChild(lockedImg);
		}
		
		private function initEvent():void
		{
			
		}
		
		/**
		 * 设置场景图片地址 
		 * @param val
		 * 
		 */
		public function set configID(val:int):void
		{
			sceneImg.source = ResConfig.mapResPath + _fieldID + "/" + val + ".jpg";
			_configID = val;
			sceneImg.width	= 130;
			sceneImg.height	= 80;
			if(!mapSp.contains(sceneImg))
			{
				sceneImg.x = sceneImg.y = 5;
				mapSp.addChild(sceneImg);
			}
		}
		
		public function get configID():int
		{
			return _configID;
		}
		
		/**
		 * 星级 
		 * @param val
		 * 
		 */
		public function set stars(val:int):void
		{
			if(_starVal == val)
			{
				return;
			}
			_starVal = val;
			//有星星先清除
			while(starSp.numChildren>0)
			{
				starSp.removeChildAt(0);
			}
			//再添加
			for(var i:int=0;i<_starVal;i++)
			{
				var starMc	:MovieClip = ResManager.newResClass("CustSkin_020") as MovieClip;
				starMc.x = 110 - 22*i;
				starMc.y = 5;
				starSp.addChild(starMc);
			}
			_isPass = true;
		}
		
		private function onLoad(val:Clip):void
		{
			val.width = val.height = 15;
		}
		
		/**
		 * 区域ID 
		 * @param val
		 * 
		 */
		public function set fieldID(val:String):void
		{
			_fieldID = val;
		}
		
		/**
		 * 是否锁定 
		 * @param val
		 * 
		 */
		public function set locked(val:Boolean):void
		{
			_locked = val;
			if(val)
			{
				addChild(lockedImg);
				sceneImg.filters = [Filter.GRAY];
			}
			else
			{
				if(contains(lockedImg))
				{
					removeChild(lockedImg);
					sceneImg.filters = null;
				}
			}
		}
		
		public function get locked():Boolean
		{
			return _locked;
		}
		
		/**
		 * 是否已经通过可以挂机
		 * @return 
		 * 
		 */
		public function get isPass():Boolean
		{
			return _isPass;
		}
	}
}